﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Web_Pages_UserControls_CreatePost : System.Web.UI.UserControl
{
    private Users user;
    private UsersBLL usersBLL;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["User"] != null)
        {
            this.user = (Users)Session["User"];
            this.usersBLL = new UsersBLL();   
        }
    }

    protected void btnPost_Click(object sender, EventArgs e)
    {
        string contents = this.txtContents.Text.Trim();

        if (contents.Length == 0)
        {
            Response.Write("<script>alert('Bạn chưa nhập nội dung')</script>");
        }
        else
        {
            bool privacy = true;
            if (rbPrivate.Checked)
            {
                privacy = false;
            }
            
            bool result = this.usersBLL.GetIPosts.CreatePost(this.user, contents, privacy);

            if (result)
            {

            }
            else 
            {
                Response.Write("<script>alert('Lỗi hệ thống')</script>");
            }
        }
    }
}